package components.toolbar
{
	import capricornus.components.ComponentsManager;
	import capricornus.core.StageManager;
	import capricornus.events.StageEvent;
	
	import components.map.MapController;
	
	import flash.events.MouseEvent;

	public class ToolBarController
	{
		public static var instance:ToolBarController;
		
		private var _view:ToolBarView;
		
		public function ToolBarController()
		{
			init();
		}
		
		private function init():void
		{
			instance = this;
			
			_view = new ToolBarView( ComponentsManager.instance.foreLayer );
			_view.show();
			
			_view.addEventListener( MouseEvent.CLICK, onClickView, false, 0, true );
			StageManager.instance.addEventListener( StageEvent.RESIZE, onResize, false, 0, true );
		}
		
		public function get width():int
		{
			return _view.width;
		}
		
		private function onClickView( e:MouseEvent ):void
		{
			var name:String = e.target.name;
			if( name=="btnopen" )
			{
				MapController.instance.open();
			}
			else if( name=="btnsave" )
			{
				MapController.instance.saveAs();
			}
			else if( name=="btnsaveas" )
			{
				MapController.instance.saveAs();
			}
			else if( name=="btnnew" )
			{
				MapController.instance.news();
			}
			else if( name=="test" )
			{
				test();
			}
		}

		private var _isTest:Boolean = false;
		private function test():void
		{
		}
		
		private function onResize( e:StageEvent ):void
		{
			_view.back.height = StageManager.stageHeight;
		}
	}
}












